package cn.easybuy.service.user;

import java.util.List;

import cn.easybuy.dao.NewsDao;
import cn.easybuy.dao.UserDao;
import cn.easybuy.dao.impl.UserDaoImpl;
import cn.easybuy.entity.User;
import cn.easybuy.utils.DataSourceUtil;

public class UserServiceImpl implements UserService {

	@Override
	public User findOneUser(String name,String pwd) {
		UserDao userDao = new UserDaoImpl(DataSourceUtil.getConnection());
		return userDao.findUser(name, pwd);
	}

	@Override
	public int registerUser(User user) {
		UserDao userDao = new UserDaoImpl(DataSourceUtil.getConnection());
		return userDao.registerUser(user);
	}

	@Override
	public int delUser(int userId) {
		UserDao userDao = new UserDaoImpl(DataSourceUtil.getConnection());
		return userDao.delUser(userId);
	}

	@Override
	public List<User> findAllUser() {
		UserDao userDao = new UserDaoImpl(DataSourceUtil.getConnection());
		return userDao.findAllUser();
	}

	@Override
	public User findToID(String id) {
		UserDao userDao = new UserDaoImpl(DataSourceUtil.getConnection());
		return userDao.findToID(id);
	}

	@Override
	public int updateUser(User user) {
		UserDao userDao = new UserDaoImpl(DataSourceUtil.getConnection());
		return userDao.updateUser(user);
	}

	@Override
	public List<User> getPageList(int pageNo, int pageSize) {
		UserDao userDao = new UserDaoImpl(DataSourceUtil.getConnection());
		return userDao.getPageList(pageNo, pageSize);
	}

	@Override
	public int getDataNum() {
		UserDao userDao = new UserDaoImpl(DataSourceUtil.getConnection());
		return userDao.getDataNum();
	}

	@Override
	public boolean findUser(String name) {
		 	UserDao dao = new UserDaoImpl(DataSourceUtil.getConnection());
		    int isExit = dao.findUser(name);
		    return isExit > 0 ? true : false;
		   
	}

	@Override
	public boolean getPhone(String name, String phone) {
		UserDao dao = new UserDaoImpl(DataSourceUtil.getConnection());
	    boolean isExit = phone.equals(dao.getPhone(name));
	    return isExit;
	}

	@Override
	public int updatePwd(String userName, String pwd) {
		UserDao dao = new UserDaoImpl(DataSourceUtil.getConnection());
	    return dao.updatePwd(userName, pwd);
	}
}
